package cn.fxyz.service.impl;

import cn.fxyz.dao.UserDao;
import cn.fxyz.entity.User;
import cn.fxyz.service.UserService;
import cn.fxyz.util.MailUtils;
import cn.fxyz.util.UUIDUtils;

public class UserServiceImpl implements UserService {
	private UserDao userDao;
	public UserDao getUserDao() {
		return userDao;
	}
	public void setUserDao(UserDao userDao) {
		this.userDao = userDao;
	}
	//登录
	public User findByUser(User user) {
		return userDao.selectByUser(user);
	}
	//通过id查询用户信息
	public User findById(int uid) {
		return userDao.selectById(uid);
	}
	//用户注册
	public void add(User user) {
		user.setCode(UUIDUtils.getUUID()+UUIDUtils.getUUID());
		user.setState("0");
		MailUtils.sendMail(user.getEmail(), user.getCode());
		userDao.insert(user);
	}
	//激活码激活
	public User findByCode(String code) {
		return userDao.selectByCode(code);
	}
	//修改用户信息
	public void modify(User existUser) {
		userDao.update(existUser);
	}
	//通过账号查询用户信息
	public User findUserByUsername(User user) {
		return userDao.findByUsername(user.getUsername());
	}
	
	
}
